package Dialogs
{
	import flash.display.Sprite;
	import flash.events.Event;
	
	import mx.containers.Panel;
	import mx.core.Application;
	import mx.events.FlexMouseEvent;
	import mx.managers.PopUpManager;

	public class DialogBox extends Panel
	{
		[Inspectable]
		public var clickOutsideCloses:Boolean = false;
		
		public function DialogBox()
		{
			super();
			this.styleName = "dialogBox";
		}
		
		public function show():void
		{
			PopUpManager.addPopUp(this, Sprite(Application.application), true);
			PopUpManager.centerPopUp(this);
			addEventListener(FlexMouseEvent.MOUSE_DOWN_OUTSIDE, clickOutHandler);
			
		}
		public function hide():void
		{
			PopUpManager.removePopUp(this);
			removeEventListener(FlexMouseEvent.MOUSE_DOWN_OUTSIDE, clickOutHandler);
		}
		
		protected function clickOutHandler(evt:Event):void
		{
			if(clickOutsideCloses)
				hide();
		}
	}
}